/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package domain;

import java.io.BufferedReader;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ParaSait
 */
public class ServerListener implements Runnable {

    private BufferedReader reader;
    private Client client;
    private boolean run;

    public ServerListener(BufferedReader reader, Client client) {
        this.reader = reader;
        this.client = client;
    }

    @Override
    public void run() {
        run = true;

        while (run) {
            if (reader != null) {
                String state = "";
                try {
                    state = reader.readLine();
                    System.out.println(state);
                } catch (IOException ex) {
                    ex.printStackTrace();
                    //observableManager.updateMessage("Connection with server failed");
                }
                
                if (state.equals("receiveFile")) {
                    client.acceptFile();
                } else if (state.equals("deleteFile")) {
                    client.deleteFile();
                }
            }
        }
    }

    public void stop() {
        run = false;
    }
}
